export default {
	namespaced: true,

	//数据
	state: () => ({
		address: JSON.parse(uni.getStorageSync('address') || '{}'),
		token:uni.getStorageSync('token'),
		userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		redirectinfo:null
	}),

	//方法
	mutations: {
		//更新收货地址
		updateAddress(state, address) {
			state.address = address;
			//调用持久化存储
			this.commit('m_user/saveAddressToStorage');
		},
		//持久化存储 address
		saveAddressToStorage(state) {
			console.log("持久化保存", state.address)
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		undateUserInfo(state, userinfo) {
			state.userinfo = userinfo;
			this.commit('m_user/saveUserInfoStorage');
		},
		saveUserInfoStorage(state) {
			uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
		},
		undateToken(state, token) {
			state.token = token;
			//调用持久化存储
			this.commit('m_user/saveTokenStorage');
		},
		saveTokenStorage(state) {
			console.log("token保存成功")
			uni.setStorageSync('token', state.token)
		},
		updateRedirectInfo(state,info){
				state.redirectinfo = info;
				console.log("保存跳转的页面",info)
				this.commit('m_user/saveRedirectInfo');
		},
		saveRedirectInfo(state){
			uni.setStorageSync('redirect',state.redirectinfo)
		}
	},

	getters: {
		addstr(state) {
			if (!state.address.provinceName) return ''

			return state.address.provinceName +
				state.address.cityName +
				state.address.countyName +
				state.address.detailInfo
		}
	}
}
